package com.shisfish.utils;

import com.shisfish.domain.Chinese;
import com.shisfish.domain.English;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;

/**
 * @author shisfish
 * @date 2020/1/17
 */
public class OrikaUtil {

    public static MapperFactory mapperFactory;

    static {
        mapperFactory = new DefaultMapperFactory.Builder().build();
    }

    public static <S, D> D map(S s, Class<D> dClass) {
        MapperFacade mapperFacade = mapperFactory.getMapperFacade();
        return mapperFacade.map(s, dClass);
    }

    public static void main(String[] args) {
        mapperFactory.classMap(Chinese.class, English.class)
                .field("chinese", "english")
                .byDefault()
                .register();
        Chinese chinese = new Chinese();
        chinese.setId(1);
        chinese.setDescript("descript");
        chinese.setName("name");
        chinese.setChinese("my name is huangshun");
        English map = map(chinese, English.class);
        System.out.println(map);
        // English{id=1, name='name', descript='descript', english='my name is huangshun'}
    }

}
